package totalMoney;

public class Solution {
    public int totalMoney(int n) {
        int money=0;
        int monday=0;
        int lastMonday=0;
        for (int i = 0; i < n; i++) {
            if(n%7==0){
                monday=lastMonday+1;
                lastMonday=monday;
            }
            money+=(monday+i);
        }
        return money;
    }
}
// 等差数列优化
//class Solution {
//    public int totalMoney(int n) {
//        // 所有完整的周存的钱
//        int weekNumber = n / 7;
//        int firstWeekMoney = (1 + 7) * 7 / 2;
//        int lastWeekMoney = firstWeekMoney + 7 * (weekNumber - 1);
//        int weekMoney = (firstWeekMoney + lastWeekMoney) * weekNumber / 2;
//        // 剩下的不能构成一个完整的周的天数里存的钱
//        int dayNumber = n % 7;
//        int firstDayMoney = 1 + weekNumber;
//        int lastDayMoney = firstDayMoney + dayNumber - 1;
//        int dayMoney = (firstDayMoney + lastDayMoney) * dayNumber / 2;
//        return weekMoney + dayMoney;
//    }
//}
